package com.itita.ww2.core;

import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.itita.ww2.enums.WW2ExceptionCode;

public class WW2Exception extends Exception {
	private static final long serialVersionUID = -4090752162497502448L;
	private WW2ExceptionCode exCode;
	private ISFSObject retObj;

	public WW2Exception() {
		super("Unknown Error!");
		this.exCode = WW2ExceptionCode.INVALID_OPT;
	}

	public WW2Exception(WW2ExceptionCode code) {
		super("Custom Error!");
		this.exCode = code;
	}

	public WW2Exception(WW2ExceptionCode code, String errDesc) {
		super(errDesc);
		this.exCode = code;
	}

	public WW2Exception(WW2ExceptionCode code, ISFSObject retObj) {
		this(code, retObj, "Unknown Error!");
	}

	public WW2Exception(WW2ExceptionCode code, ISFSObject retObj, String errDesc) {
		super(errDesc);
		this.retObj = retObj;
		this.exCode = code;
	}

	public WW2ExceptionCode getExCode() {
		return exCode;
	}

	public ISFSObject getRetObj() {
		return retObj;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(this.exCode.getValue()).append(":").append(this.exCode.name());
		sb.append(" | ").append(this.getMessage());
		if (this.retObj != null && this.retObj.size() > 0) {
			sb.append(" | ").append(this.retObj.toJson());
		}
		return sb.toString();
	}
}
